//
//  NewShouYiMXZhuViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/13.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewShouYiMXZhuViewController.h"
#import "JTCSM.h"
#import "MyInfoView.h"
#import "MyDoubleLabelView.h"
#import "NewPaiHangViewController.h"
#import "NewJiaoYiInfoViewController.h"

static CGFloat myinfoHeight = 50;
@interface NewShouYiMXZhuViewController ()
{
    UIImageView *headerImageView;
}
@property (nonatomic,strong) UILabel *moneyLabel;
@property (nonatomic,strong) MyDoubleLabelView *bottomDoubleView;
@end

@implementation NewShouYiMXZhuViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERWith*0.69333)];
    headerImageView.image = [UIImage imageNamed:@"shouyiBackgroundImage.png"];
    [self.view addSubview:headerImageView];
    UIImage * firstImage = [UIImage imageNamed:@"fanhui.png"];
    CGRect firstFrame = CGRectMake(20, 20, 50, 44);
    CGFloat width = firstFrame.size.width;
    CGFloat height = firstFrame.size.height;
    CGFloat imagesize = 20;
    UIButton * leftButton = [[UIButton alloc]initWithFrame:firstFrame];
    [leftButton setImage:firstImage forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(gotBack) forControlEvents:UIControlEventTouchUpInside];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake((height-imagesize)/2, 0, (height-imagesize)/2, (width-imagesize));
    [self.view addSubview:leftButton];
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(0, 20, KCONTROLLERWith, 44) text:@"收益明细" font:20 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(255, 255, 255, 1) backgroundColor:nil];
    [self.view addSubview:titleLabel];
    
    NSString *moneyStr = @"¥520.00";
    float  fontsize = 24;
    CGRect rect = [df labelHeightWithContent:moneyStr width:1000 font:fontsize];
    
    self.moneyLabel = [UILabel initWithFrame:CGRectMake(0, 80, KCONTROLLERWith, rect.size.height) text:moneyStr font:fontsize textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:nil];
    [self.view addSubview:self.moneyLabel];
    
    [self layoutZhuzhaungTu];
    
    // Do any additional setup after loading the view.
}


- (void)layoutZhuzhaungTu{
//   230  60 45
    int number = 12;
    int max = 12;
    CGFloat labelWidth = KCONTROLLERWith/max;
    CGFloat space = (KCONTROLLERWith-labelWidth*number)/2;
    
    for (int i=number; i >0; i--) {
        [self setZhuangHeight:(float)[self getRandomNumber:1 to:10]/10.0 backgroundColor:(i==number?[UIColor whiteColor]:RGBACOLOR(255, 255, 255, .5)) labeltext:[NSString stringWithFormat:@"%d",i] labelFrame:CGRectMake(space+labelWidth*(i-1), headerImageView.LC_height*0.8846, labelWidth, headerImageView.LC_height*0.08653)];
    }
    
    NSArray *array = @[@"交易收益（元）",@"拓客收益（元）",@"互动奖励（元）"];
    MyInfoView *view1;
    for (int i = 0; i < array.count; i++) {
        view1 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KCONTROLLERWith*0.69333+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:nil title:array[i]placeholder:nil isShowLabel:labelType radioBtnIndex:0 GroupId:@""];
        view1.tag = 100+i;
        view1.userInteractionEnabled = YES;
        [df addTapGestureRecognizerWithTarget:self action:@selector(gotonextVC:) andaddView:view1];
        [self.view addSubview:view1];
    }
    UIView *bottomview = [[UIView alloc]initWithFrame:CGRectMake(20, KVIEW_Y(view1)+34, KCONTROLLERWith-40, 72)];
    bottomview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    [self.view addSubview:bottomview];
    [df layerWithView:bottomview radius:5 width:0 color:nil];
    bottomview.userInteractionEnabled = YES;
    self.bottomDoubleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(10, 0, bottomview.LC_width/2, bottomview.LC_height) leftTitleFontsize:12 titlecolor:[df colorWithHexString:@"999999" alpha:1] contentFontsize:28 contentcolor:[df colorWithHexString:@"f77948" alpha:1]];
    [bottomview addSubview:self.bottomDoubleView];
    [self.bottomDoubleView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"今日收益（元）",KDoubleLabelContent:@"52.54"} changeLabelY:10];
    CGFloat bottomspace = 0;
    CGFloat imagesize = (bottomview.LC_height-2*bottomspace);
    UIImageView *tapImageV = [[UIImageView alloc]initWithFrame:CGRectMake(bottomview.LC_width-bottomspace-imagesize, bottomspace, imagesize, imagesize)];
    tapImageV.userInteractionEnabled = YES;
    tapImageV.image = [UIImage imageNamed:@"查看-排行榜.png"];
    [bottomview addSubview:tapImageV];
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotoNewPaiHangViewController) andaddView:tapImageV];
}
- (void)gotoNewPaiHangViewController{
    NewPaiHangViewController *vc = [[NewPaiHangViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(int)getRandomNumber:(int)from to:(int)to
{
    return (int)(from + (arc4random() % (to - from + 1)));
}

- (void)setZhuangHeight:(float)height backgroundColor:(UIColor *)color labeltext:(NSString *)text labelFrame:(CGRect)rect{
    NSLog(@"%f",height);
    CGFloat zhuheight = headerImageView.LC_height*0.4423;
    UILabel *titleLabel = [UILabel initWithFrame:rect text:text font:11 textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:nil];
    [self.view addSubview:titleLabel];
    CGFloat zhuWidth = 10;
    UIView *zhuView = [[UIView alloc]initWithFrame:CGRectMake(rect.origin.x+(rect.size.width-zhuWidth)/2, zhuheight+zhuheight*(1-height), zhuWidth, zhuheight*height)];
    zhuView.backgroundColor = color;
    [df layerWithView:zhuView radius:zhuWidth/2 width:0 color:nil];
    [self.view addSubview:zhuView];
}

- (void)gotonextVC:(UITapGestureRecognizer *)tap{
    NSInteger tagnumber = [tap view].tag-100;
    switch (tagnumber) {
        case 0:
            [self gotoAboutVCWithType:JiaoYiType titleName:@"交易收益"];
            break;
        case 1:
            [self gotoAboutVCWithType:TuoKeType titleName:@"拓客收益"];
            break;
        case 2:
            [self gotoAboutVCWithType:HuDongType titleName:@"互动收益"];
            break;
            
        default:
            break;
    }
    
}
- (void)gotoAboutVCWithType:(ShouYiType)type titleName:(NSString *)name{
    NewJiaoYiInfoViewController *vc = [[NewJiaoYiInfoViewController alloc]init];
    vc.nameTitle = name;
    vc.mytype = type;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
